package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.entity.Bo.ApplyListBo;
import com.hzncc.scaffold.entity.Other.Trainingapply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzncc.scaffold.entity.Vo.MyTrainingVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 培训申请表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Component
public interface TrainingapplyMapper extends BaseMapper<Trainingapply> {


    @Select("SELECT\n" +
            "\t`trainingapply`.`id`,\n" +
            "\t`trainingapply`.`pubTime`,\n" +
            "\t`trainingapply`.`createTime`,\n" +
            "\t`trainingapply`.`status`,\n" +
            "\t`creator`.`id` AS `creatorId`,\n" +
            "\t`creator`.`name` AS `creatorName`,\n" +
            "\t`creator`.`account` AS `creatorAccount`,\n" +
            "\t`creator`.`realname` AS `creatorRealname`,\n" +
            "\t`creator`.`instituteName` AS `creatorInstituteName`,\n" +
            "\t`creator`.`idCardNum` AS `creatorIdCardNum`,\n" +
            "\t`creator`.`telephone` AS `creatorTelephone`,\n" +
            "\t`publisher`.`id` AS `publisherId`,\n" +
            "\t`publisher`.`name` AS `publisherName` \n" +
            "FROM\n" +
            "\t`trainingapply` AS `trainingapply`\n" +
            "\tLEFT OUTER JOIN `user` AS `creator` ON `trainingapply`.`userId` = `creator`.`id`\n" +
            "\tLEFT OUTER JOIN `user` AS `publisher` ON `trainingapply`.`publisherId` = `publisher`.`id` \n ${ew.customSqlSegment}" +
            "ORDER BY\n" +
            "\t`trainingapply`.`createTime` DESC,\n" +
            "\t`trainingapply`.`id` DESC ")
    public List<ApplyListBo> applyList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    @Select("SELECT\n" +
            "\t`trainerapply`.`id`,\n" +
            "\t`trainerapply`.`status`,\n" +
            "\t`oneplusxtraining`.`title` AS `title`,\n" +
            "\t`oneplusxtraining`.`startTime` AS `startTime`,\n" +
            "\t`oneplusxtraining`.`endTime` AS `endTime` \n" +
            "FROM\n" +
            "\t`trainerapply` AS `trainerapply`\n" +
            "\tLEFT OUTER JOIN `oneplusxtraining` AS `oneplusxtraining` ON `trainerapply`.`trainingId` = `oneplusxtraining`.`id`  ${ew.customSqlSegment}")
    public List<MyTrainingVo> myTraining(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT\n" +
            "\t`trainingclass->news`.`id` AS `id`,\n" +
            "\t`trainingapply`.`status`,\n" +
            "\t`trainingclass`.`startTime` AS `startTime`,\n" +
            "\t`trainingclass`.`endTime` AS `endTime`,\n" +
            "\t`trainingclass->news`.`title` AS `title` \n" +
            "FROM\n" +
            "\t`trainingapply` AS `trainingapply`\n" +
            "\tINNER JOIN `trainingclass` AS `trainingclass` ON `trainingapply`.`classId` = `trainingclass`.`id`\n" +
            "\tLEFT OUTER JOIN `news` AS `trainingclass->news` ON `trainingclass`.`newsId` = `trainingclass->news`.`id`  ${ew.customSqlSegment}")
    public List<MyTrainingVo> myTrainingPlus(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

}
